/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.forms.renderers;

import TimeRecording.business.IntegerTimeRange;
import TimeRecording.business.IntegerTimeRangeArrayList;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author david
 */
public class HourlySliceRenderer extends DefaultTableCellRenderer {

    private final static Color SLICE_COLOR = new Color(0xB0, 0xFF, 0xB0);
    private IntegerTimeRangeArrayList periods;

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {

        periods = (IntegerTimeRangeArrayList)value;
        return this;
    }

    @Override
    public void paint(Graphics g) {

        super.paint(g);
        
        Color savedColour = g.getColor();

        g.setColor(SLICE_COLOR);
        for (IntegerTimeRange period : periods) {
            int y1 = (period.getMinutesFrom() * getHeight()) / 60;
            int y2 = (period.getMinutesTo() * getHeight()) / 60;
            g.fillRect(0, y1, getWidth(), y2 - y1);
        }

        g.setColor(Color.LIGHT_GRAY);

        int dy = Math.round(getHeight() / 4);
        g.drawLine(0, dy, getWidth(), dy);

        dy = Math.round(2 * getHeight() / 4);
        g.drawLine(0, dy, getWidth(), dy);

        dy = Math.round(3 * getHeight() / 4);
        g.drawLine(0, dy, getWidth(), dy);

        g.setColor(savedColour);
    }
}
